package com.bid.base.common.entity;

import com.bid.base.common.util.Stringer;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * <strong>Description : </strong> <br>
 * <p>
 * <strong>北京正源德标科技信息有限责任公司</strong> <br>
 * </p>
 * <br>
 *
 * @author : zhaots
 * @date Date : 2020年12月07日 18:22
 * 修改人 修改日期 修改描述<br>
 * -------------------------------------------<br>
 * <br>
 * <br>
 */

/**
 * 1.每一个项目用redis 有一个前缀
 * <p>
 * 2.达到目的：没有前缀在此注册的可以直接删除
 *
 * @author Administrator
 */
public class CommonEnums {



    public static final String REFRESH_TOKEN_FLAG = "REFRESH_TOKEN_FLAG";
    public static final String TOKEN_PREFIX = "OCTO";
    public static final String NO_LOGIN_URL = "/api/login/nologin";

    public static final String FILE_ROOT = "/api/login/nologin";

//    public static final String USER_NAME_IN_TOKEN = "USER_NAME";
//    public static final String DEPT_ID_IN_TOKEN = "DEPT_ID";
//    public static final String SUBJECTTYPE_ID_IN_TOKEN = "SUBJECT_TYPE";

    /**
     * 适合 0 1的情况
     * 0 未作，未发生，未完成，未删除等。。
     * 1 已经发生
     */
    @Getter
    public enum Done {
        undo,done;
    }

    /**
     * 登录类型
     */
    public  enum LoginType {
        USERPWD("1", "用户名密码登录"),
        MOBILE("2", "手机号验证码登录"),
        CA_ZZHL("3-1", "中招互联CA登录"),
        CA_BJCA("3-2", "北京CA登录"),
        WECHAT("4", "微信登录");


        private String code;
        private String desc;

        private LoginType(String code, String desc) {
            this.code = code;
            this.desc = desc;
        }


        public String getCode() {
            return code;
        }
        public static LoginType parseOf(String code) {
            LoginType[] var1 = LoginType.values();
            for (LoginType each:var1) {
                if (each.getCode().equals(code)){
                    return each;
                }
            }
            return null;
        }
    }



    /**
     * 职务类型
     * 0：普通员工；1：部门经理；3.运营管理员
     */
    public  enum JobType {
        COMMON_EMPLOYEE("0", "普通员工"),
        DEPT_MANAGER("1", "部门经理"),
        OPER_ADMIN("3", "运营管理员");


        private String code;
        private String desc;

        private JobType(String code, String desc) {
            this.code = code;
            this.desc = desc;
        }


        public String getCode() {
            return code;
        }
        public static JobType parseOf(String code) {
            JobType[] var1 = JobType.values();
            for (JobType each:var1) {
                if (each.getCode().equals(code)){
                    return each;
                }
            }
            return null;
        }
    }

    /**
     * 密码重置标志位
     * 密码重置标志位（0：需要修改、1：不需要修改）
     */
    public  enum RestPasswordFlag {
        NEEDUPDATE("0", "需要修改密码"),
        NONEEDUPDATE("1", "不需要修改密码");

        private String code;
        private String desc;

        private RestPasswordFlag(String code, String desc) {
            this.code = code;
            this.desc = desc;
        }


        public String getCode() {
            return code;
        }
        public static RestPasswordFlag parseOf(String code) {
            RestPasswordFlag[] var1 = RestPasswordFlag.values();
            for (RestPasswordFlag each:var1) {
                if (each.getCode().equals(code)){
                    return each;
                }
            }
            return null;
        }
    }



    @Getter
    public enum ToKenScopeAndLimit{
        /**
         * pc端浏览器 AUTH_PC，表示pc端，  1 表示允许登录数量
         *
         */
        PC("AUTH_PC",1,""),
        /**
         * 2022-6-8 小需求
         *
         */
        AUTH_BID_ELEC("AUTH_BID_ELEC",1,""),
        AUTH_BID_GOV("AUTH_BID_GOV",1,""),
        AUTH_BID_EXAM("AUTH_BID_EXAM",1,""),
        AUTH_BID_PLAT("AUTH_BID_PLAT",1,""),
        /**
         * 招标工具
         *
         */
        AUTH_TOOL_TENDER("AUTH_TOOL_TENDER",1,"tool-tender"),
        /**
         * 投标工具
         *
         */
        AUTH_TOOL_BIDDING("AUTH_TOOL_BIDDING",1,"tool-bidding"),

        H5_WECHAT("H5_WECHAT",1,""),
        ;
        private String scope;
        private Integer counter;
        /**
         * 北京正源德标科技信息有限责任公司
         * @return
         * @创建时间 2021/8/26
         * @创建人 zhaots
         * @描述 如果一个scope下面只有一个微服务，这么表示前端少穿一个参数，招标投标可以同时登录这个才有用
         */
        private String subSys;
        private ToKenScopeAndLimit(String scope,Integer counter,String subSys){
            this.scope = scope;
            this.counter = counter;
            this.subSys = subSys;
        }

        public static ToKenScopeAndLimit parseOf(String scope) {
            if (Stringer.isNullOrEmpty(scope)) {
                return null;
            }

            ToKenScopeAndLimit[] values = ToKenScopeAndLimit.values();
            for (ToKenScopeAndLimit each : values) {
                if (each.getScope().equals(scope)) {
                    return each;
                }
            }
            return null;
        }

        public static boolean isValild(String scope){
            boolean res =false;
            if(Stringer.isNullOrEmpty(scope)){
                return res;
            }
            ToKenScopeAndLimit[] values = ToKenScopeAndLimit.values();
            for (ToKenScopeAndLimit each:values) {
                if(each.getScope().equals(scope)){
                    return true;
                }
            }
            return res;

        }
        /**
         * limiter
         * Map
         * key                   value
         *
         * acid _ userid + suffix    sha（userAgent）
         * ============================================================
         *
         * acid _ userid
         * 		_TOOL_ZHAO sha（userAgent）
         *
         * id  token 这样也行
         *
         */
        //acid _ userid + sh
        public String getType(String artifactId,String userId,String suffix){
            return artifactId.toUpperCase() + "_" + userId + "_" + suffix;
        }
    }
    @Getter
    public enum FilePathType {
        local_server, alioss_server,tencent_cos,idc;
    }

    //colove_resources
    @Getter
    public enum FileType {

        image_jpeg(1, "image/jpeg", "jpg"),
        image_png(2, "image/png", "png");
        private int code;
        private String name;
        private String suffix;

        FileType() {
        }

        FileType(int code, String name, String suffix) {
            this.code = code;
            this.name = name;
            this.suffix = suffix;
        }

        public static FileType parseOf(String name) {
            for (FileType enumValue : FileType.values()) {
                if (enumValue.getName().equalsIgnoreCase(name)) {
                    return enumValue;
                }
            }
            return null;
        }
    }

    @Getter
    public enum MdcKey {
        USEID("USER_ID","用户id"),
        SCOPE("SCOPE","SCOPE"),
        USER_NAME("USER_NAME","用户名"),
        DEPT_ID("DEPT_ID","部门id"),
        SUBJECT_TYPE("SUBJECT_TYPE","主体类型"),
        //2021-4-7
        EXPERT_ID("EXPERT_ID","专家id"),
        LOGIN_TYPE("LOGIN_TYPE","登录类型"),
        //合并 登录随机数，和登录相互覆盖有关
        L_RANDOM_STR("L_RANDOM_STR","登录随机数"),
        AUTH_CODE("AUTH_CODE","AUTH_CODE"),
        //
        EXPIRE_AT_MILLIS("EXPIRE_AT_MILLIS","什么时候过期"),
        EXPIRE_TIME_MILLIS("EXPIRE_TIME_MILLIS","多长时间过期"),
        //2021-4-28
        LEGAL_ID("LEGAL_ID","法人id"),
        //2021-5-21 中招互联的CA登录tid
        ZZHLCA_LOGIN_TID("ZZHL_CA_LOGIN_TID","中招互联登录tid"),
        BJCA_LOGIN_TID("BJCA_LOGIN_TID","预留给北京ca的登录id，以后可以改动"),
        //直接调用文件服务 wuao
        TOKEN("TOKEN","token本身"),
        /**
         * 审核 工作台 展示使用     B_OCTO_USER --> NAME
         */
        NAME("NAME","名字"),
        /**
         *  CAPACITY_TYPE
         */
        CAPACITY_TYPE("CAPACITY_TYPE","职务类型"),
        /**
         * @创建时间 2021/10/19
         * @创建人 zhaots
         * @描述 监督相关
         * 2022-6-28
         * 监督部门代码 --》 监督主体代码
         * 监督部门名称 --》 监督主体代码
         * 2022-6-28  组织机构代码，组织机构名称--企业名称--主体名称  这里虽然set进去了，但是不一定是监督相关的
         *如果需要用，要配合subjectType使用
         */
        SURVEILLANCE_DEPT_CODE("SURVEILLANCE_DEPT_CODE","监督主体代码"),
        SURVEILLANCE_DEPT_NAME("SURVEILLANCE_DEPT_NAME","监督主体名称"),

        ORIGIN("ORIGIN","来源，标识从哪个系统登录"),

        GOV_EXPERT_ID("GOV_EXPERT_ID","政府专家id"),
        //
        SUBJECT_IDS("SUBJECT_IDS","主体ids"),
        SUBJECT_NAMES("SUBJECT_NAMES","主体names"),

        DOCKING_SYSTEM_CODE("DOCKING_SYSTEM_CODE","对接系统标识"),
        //0318需求之后
        ENT_ADMIN_FLAG("ENT_ADMIN_FLAG","是否启用：0（禁用）；1（启用）"),


        EXT3("EXT3"),
        EXT4("EXT4")
        ;
        private String name;
        private String desc;
        private MdcKey(String name){
            this.name=name;
        }
        private MdcKey(String name,String desc) {
            this.name = name;
            this.desc = desc;
        }

    }


    @Getter
    public enum AuthType {
        BASE("0", "snsapi_base", "静默授权"), USER("1", "snsapi_userinfo", "显式授权");
        private String id;
        private String code;
        private String name;

        private AuthType(String id, String code, String name) {
            this.id = id;
            this.code = code;
            this.name = name;
        }

        private static Map<String, AuthType> valueMap = new HashMap<String, AuthType>();

        static {
            for (AuthType _enum : AuthType.values()) {
                valueMap.put(_enum.id, _enum);
            }
        }

        public static AuthType parseOf(String id) {
            for (AuthType item : values())
                if (item.getId().equals(id))
                    return item;
            throw new IllegalArgumentException("AuthType异常错误代码[" + id + "]不匹配!");
        }

    }

    @Getter
    public enum Whether {
        NO("0", "否"), YES("1", "是");

        private String code;
        private String desc;

        Whether(String code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public static Whether parseOf(String code) {
            for (Whether item : values()){
				if (item.getCode().equals(code)){
					return item;
				}
			}

            throw new IllegalArgumentException("Whether[" + code + "]不匹配!");
        }

    }


}
